/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tradeplus.admin.service;

import java.util.List;

import com.tradeplus.admin.dao.CityDao;
import com.tradeplus.admin.dao.CountryDao;
import com.tradeplus.admin.dao.StateDao;
import com.tradeplus.admin.dao.SystemPropertyDao;
import com.tradeplus.admin.model.City;
import com.tradeplus.admin.model.Country;
import com.tradeplus.admin.model.State;
import com.tradeplus.admin.model.SystemProperty;

/**
 *
 * @author ronnie
 */
public class AdminServiceImpl implements AdminService {
    
    private SystemPropertyDao systemPropertyDao;
    private CountryDao countryDao;
    private StateDao stateDao;
    private CityDao cityDao;
    
    
    
    public void setCountryDao(CountryDao countryDao) {
		this.countryDao = countryDao;
	}
    

	public void setStateDao(StateDao stateDao) {
		this.stateDao = stateDao;
	}


	public void setCityDao(CityDao cityDao) {
		this.cityDao = cityDao;
	}


	/**
     * Retrieves System Property value by key.
     *
     * @param key
     * @return System Property Value
     */
    @Override
    public String getValueForSystemProperty(String key) {

        String value = null;
        SystemProperty property = this.getSystemProperty(key);

        if(property!=null){
            value = property.getValue();
        }
        return value;
    }
    
    /**
     * Retrieve SystemProperty object for given key.
     *
     * @param key
     * @return SystemProperty object
     */
    private SystemProperty getSystemProperty(String key) {
        return systemPropertyDao.findByKey(key);
    }

	@Override
	public void saveCountry(Country country) {
		countryDao.saveCountry(country);
	}

	@Override
	public List<Country> loadCountry() {
		return countryDao.loadCountry();
	}
	
	@Override
	public Country loadCountryById(Long countryId) {
		return countryDao.loadCountryById(countryId);
	}

	@Override
	public void saveState(State state) {
		stateDao.saveState(state);
	}

	@Override
	public List<State> loadState() {
		return stateDao.loadState();
	}

	@Override
	public State loadStateById(Long stateId) {
		return stateDao.loadStateById(stateId);
	}
	
	@Override
	public void saveCity(City city) {
		cityDao.saveCity(city);
	}

	@Override
	public List<City> loadCity() {
		return cityDao.loadCity();
	}

}
